
NP      =8
NAME    =map
RNAME   =mapreader
MN      =model_new
QUEUE   =mpi_2
MPIRUN  =bsub -a intelmpi -q $(QUEUE) -n $(NP) mpirun.lsf
FC      =mpiifort
MAPPATH =../../MAP_LIB
OPT     =-O2 -warn -traceback -vec-report0 -module $(MAPPATH)
#for checking
OPT2    =-O2 -warn -traceback -vec-report0 -check bounds -check pointers -check uninit -module $(MAPPATH)
CHECK   =
ifdef CHECK
   OPT=$(OPT2)
endif

include $(MAPPATH)/Makefile.p

FILES   = \
$(FILES_MAP_P) \
model_hc.f90 \
model_variables.f90 \
model_resis.f90 \
bnd_user.f90 \
damping_zone.f90

FILES_M = $(MAPPATH)/main.f90
FILES_D = $(MAPPATH)/data_manage.f90 \
          $(MAPPATH)/extremum_calculate.f90 \
          $(MAPPATH)/data_collect.f90 \
          $(MAPPATH)/write_vtk_unstructured.f90 \
          $(MAPPATH)/write_vtu_data.f90 \
          $(MAPPATH)/write_vtu_header.f90 \
          $(MAPPATH)/write_mapvis.f90

OBJS    =$(FILES:.f90=.o)
OBJS_D  =$(FILES_D:.f90=.o)
OBJS_M  =$(FILES_M:.f90=.o)

$(NAME):$(OBJS) $(OBJS_M)
	$(FC) $(OPT) -o $(NAME) $(OBJS) $(OBJS_M)
	@echo
	@echo Compile completed!

%.o:%.f90
	$(FC) $(OPT) -c -o $@ $<

run:$(NAME)
	mpiexec -n $(NP) $(PWD)/$(NAME)

submit:$(NAME)
	$(MPIRUN) $(PWD)/$(NAME)

rddt:$(OBJS_D)
	$(FC) $(OPT) -o $(RNAME) $(OBJS_D)
	mpiexec -n $(NP) $(RNAME)

new:
	mkdir -p ../$(MN)
	cp *.f90 parameters Makefile *.pro ../$(MN)

kill:
	@ bkill -r `ls output.* | awk -F '.' 'END {print $$2}'`

tail:
	@ tail -f `ls output.* | awk "END{print}"`

clean:
	rm -f $(NAME) $(RNAME) $(OBJS_D) a.out pre.exe rddt.exe *genmod* *~ *\* input *.mod *.o *.include fort.11
	rm -rf `ls -d */ 2> /dev/null`
	@echo
	@echo Clean completed!

cleanrddt:
	rm $(OBJS_D)
	@echo
	@echo Cleanrddt completed!

cleanall:
	rm -f $(OBJS) $(OBJS_M) $(OBJS_D) $(NAME) $(RNAME) a.out pre.exe rddt.exe *genmod* *~ *\* input *.mod output.* *.include fort.11
	cd $(MAPPATH); rm -f *genmod* *~ *\* input *.mod
	rm -rf `ls -d */ 2> /dev/null`
	@echo
	@echo Cleanall completed
